import java.util.PriorityQueue;

public class Congress
{
	PriorityQueue<State> pq;
	
	public Congress(int N)
	{
		pq = new PriorityQueue<State>(N);
	}
	
	// Add a state to the queue
	public void addState(String name, int pop)
	{
		pq.add(new State(name, pop));
	}
	
	// Print state and its number of seats
	public void addSeat()
	{
		State tmp = pq.poll();
		tmp.incrementSeats();
		pq.add(tmp);
	}
	
	// Print all states and their number of seats
	public void print()
	{
		for (State s: pq)
			StdOut.println(s.toString());
	}
	
	// State class
	private class State implements Comparable<State>
	{
		private String name;
		private double pop;
		private int seats;
		
		public State (String name, int pop)
		{
			this.name = name;
			this.pop = pop;
			seats = 1;
		}
			
		// Reduce the population by the given constant
		public double D()
		{
			return Math.sqrt(seats*(seats + 1));
		}
			
		// Return the state as a string
		public String toString()
		{
			return name + " " + seats;
		}
			
		// Add a seat to the state
		public void incrementSeats(){
			seats++;
		}
			
		// Compare this state to another state
		public int compareTo(State s)
		{
			return (int)((s.getPop() / s.D()) - (pop / D()));
		}
		
		// Return population
		public double getPop()
		{
			return pop;
		}
	}
	
	public static void main(String[] args) {
		Stopwatch sw = new Stopwatch();
		int N = StdIn.readInt();
		StdIn.readLine();
		int seats = StdIn.readInt()-N;	// States are created with one seat each
		StdIn.readLine();
		
		Congress cong = new Congress(N);
		
		// Add states to congress
		for (int i = 0; i < N; i++)
		{
			String name = StdIn.readLine();
			int pop = Integer.parseInt(StdIn.readLine());
			
			cong.addState(name,pop);
		}
		
		// Add seats
		while (seats > 0)
		{
			cong.addSeat();
			seats--;
		}
		cong.print();
		StdOut.println(sw.elapsedTime());
	}
}

